package com.kaesar.thread_ressmix.atomic;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

/**
 * @Author: chengk
 * @Date: 2021/8/31 12:41 上午
 */
public class Account2 {
    private volatile int money;
    private static final AtomicIntegerFieldUpdater<Account2> updater = AtomicIntegerFieldUpdater.newUpdater(Account2.class, "money");

    Account2(int initial) {
        this.money = initial;
    }

    public void increMoney() {
        updater.incrementAndGet(this);
    }

    public int getMoney() {
        return money;
    }

    @Override
    public String toString() {
        return "Account{" +
                        "money=" + money +
                        '}';
    }
}
